package com.bootdo.acitvity.DDD.domain.event;


import com.bootdo.acitvity.DDD.domain.CenterBatch;
import com.bootdo.acitvity.DDD.domain.entity.ChannelLockedStock;
import com.bootdo.acitvity.DDD.domain.entity.ShareStock;
import com.bootdo.acitvity.DDD.domain.entity.Stock;

import java.util.Date;
/**
 * @author hy
 *  创建锁定库存
 */
public class StockLockCreateStrategy implements StockUpdateStrategy {
    @Override
    public void updateStock(CenterBatch batch, Stock stockChange) {
        if(!(stockChange instanceof ChannelLockedStock)){
            throw new IllegalArgumentException();
        }
        ChannelLockedStock dto = (ChannelLockedStock) stockChange;
        ShareStock shareStock = batch.getShareStock();
        // 扣减共享库存
        ShareStock shareStockReduced = shareStock.reduce(stockChange);
        batch.setShareStock(shareStockReduced);
        // 新建锁定库存
        batch.addLockedStock(dto);

    }
}
